from django.db import models
import assets_users.models as um
import datetime


class DeviceType(models.Model):
    code = models.CharField(verbose_name='设备类型代码', max_length=10, primary_key=True, null=False)
    name = models.CharField(verbose_name='设备类型', max_length=20)

    class Meta:
        verbose_name = '设备类型'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class DeviceInfo(models.Model):
    type = models.ForeignKey(DeviceType, verbose_name='设备类型', on_delete=models.CASCADE)
    logo = models.CharField(verbose_name="品牌", max_length=20)
    version = models.CharField(verbose_name='型号', max_length=20)
    code = models.AutoField(primary_key=True, verbose_name='编号')
    dev_value = models.CharField(max_length=10, verbose_name='价值', null=True, blank=True)
    supplier = models.CharField(verbose_name='供应商', max_length=20, null=True, blank=True)
    enter_time = models.DateTimeField(verbose_name='入库时间', auto_now=False, auto_now_add=False)
    out_time = models.DateTimeField(verbose_name='出库时间', blank=True, null=True)
    unit = models.ForeignKey(um.UserUnit, verbose_name='管理科室', on_delete=models.CASCADE)
    manager = models.ForeignKey(um.UserInfo, verbose_name='管理人', on_delete=models.SET_NULL, null=True)
    place = models.CharField(verbose_name='存放位置', max_length=40, null=True, blank=True)
    image = models.ImageField(verbose_name='图片', upload_to='assets_manage/assets/%Y/%m', max_length=500, null=True,
                              blank=True)
    status = models.CharField(verbose_name='报废状态', max_length=1, choices=(('1', '正常'), ('2', '待报废'), ('3', '已报废')),
                              default='1')
    enter_user = models.CharField(verbose_name='登记人', max_length=20, null=True, blank=True)

    class Meta:
        verbose_name = '设备详情'
        verbose_name_plural = verbose_name

    def __str__(self):
        return "%s - %s - %s - %s" % (self.code, self.logo, self.version, self.place)
